package org.jimthompson.delinkious;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import del.icio.us.Delicious;
import del.icio.us.beans.Post;

public class DeliciousMarkSource implements MarkSource
{
    @SuppressWarnings("unchecked")
    public List<Mark> 
    getDeliciousPostsAfter(String name, String passwd, Date date) 
    {
        Delicious d = new Delicious(name, passwd);
        
        List l = d.getRecentPosts();
        
        System.out.println("list size = " + l.size());
        
        List<Post> lp = (List<Post>) l;
        Iterator<Post> iter = lp.iterator();
        
        while (iter.hasNext())
        {
            Post delpost = iter.next();
            Date post_date = delpost.getTimeAsDate();
            
            if (post_date.after(date)) 
            {
                System.out.println(date + "name = " + delpost.getDescription());
                
                Mark m = new Mark();
                m.m_description = delpost.getExtended();
                m.m_link = delpost.getHref();
                m.m_title = delpost.getDescription();
                m.m_tags = delpost.getTagsAsArray(" ");
                
                for (int i = 0; i < m.m_tags.length; i++)
                {
                    System.out.println(" tag: " + m.m_tags[i]);
                }
            }
        }
        
        return null;
    }
}
